package com.sfx.other.多线程样例测试;

import java.util.concurrent.Semaphore;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: sfx
 * Date: 2023-08-12
 * Time: 10:56
 */
public class TestSemaphore {
    public static void main(String[] args) {
        Semaphore semaphore = new Semaphore(3);
        for(int i =0;i<10;++i) {
            new Thread(()->{
                try {
                    semaphore.acquire();
                    System.out.println("start : " + Thread.currentThread().getName());
                    Thread.sleep(1000);
                    System.out.println("end : " + Thread.currentThread().getName());
                    semaphore.release();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            },"t" + i).start();
        }
    }
}